package ProcessScheduling;

import javax.swing.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;

public class MainFrame
{
	private JList readyList;

	private JList waitingList;
	
	private JList jobList;
	private JButton susButton;
	private JButton relaxButton;
	private JButton startButton;
	private JButton newButton;
	
	private JLabel nameLabel;
	private JLabel prorityLabel;
	private JLabel timeLabel;
	private JLabel jobLabel;
	private JLabel readyLabel;
	private JLabel waitingLabel;
	private JLabel runningLabel;
	private JLabel spaceLabel;
	private JLabel divLabel;
	private JLabel allocLabel;
	
	private JTable readyTable;
	private JTable runningTable;
	private JTable divTable;
	private JTable allocTable;
	
	
	private JTextField nameText;
	private JTextField timeText;
	private JTextField spaceText;
	private JComboBox prorityCom;
	
	private JPanel newPanel;
	private JPanel waitingPanel;
	private JPanel readyPanel;
	
	Vector jobVectorName;
	Vector jobDtoVector;
	Vector waitingVectorName;
	Vector waitingDtoVector;
	PcbDTO []readyDtoArray;
	PcbDTO []newDtoArray;
	divDTO []divDtoArray;
	PcbDTO []newSort;
	Object[][] readydata;
	Object[][] runningdata;
	Object[][] divdata;
	Object[][] allocdata;
	
	int first;
	int end;
	int point;
	PcbDTO a ;	
	public MainFrame()
	{
		a = new PcbDTO();
		first = 0;
		end = 0;
		point = 0;
		JFrame jf = new JFrame("进程调度-ws");
		Container c = jf.getContentPane();
		c.setLayout(null);
		//c.setBackground(Color.pink);
		
		newPanel = new JPanel();
		newPanel.setLayout(null);
		waitingPanel = new JPanel();
		waitingPanel.setLayout(null);
		//waitingPanel.setBackground(Color.pink);
		readyPanel = new JPanel();
		readyPanel.setLayout(null);
		
		susButton = new JButton("挂起");
		relaxButton = new JButton("释放");
		startButton = new JButton("开始");
		newButton = new JButton("新建进程");
		
		nameLabel = new JLabel("进程名");
		prorityLabel = new JLabel("优先级");
		timeLabel = new JLabel("运行时间");
		jobLabel = new JLabel("后备队列");
		readyLabel = new JLabel("就绪队列");
		waitingLabel = new JLabel("等待队列");
		runningLabel = new JLabel("运行进程");
		spaceLabel = new JLabel("需要空间");
		divLabel = new JLabel("未分分区表");
		allocLabel = new JLabel("内存分配表");
		
		nameText = new JTextField();
		timeText = new JTextField();
		spaceText = new JTextField();
		prorityCom = new JComboBox();
		prorityCom.setToolTipText("优先级");
		
		readyDtoArray = new PcbDTO[6];
		newSort = new PcbDTO[6];
		for(int i = 0; i< 6;i++)
		{
			newSort[i] = new PcbDTO();
		}
		newDtoArray = new PcbDTO[100];
		jobDtoVector = new Vector();
		jobVectorName = new Vector();
		waitingDtoVector = new Vector();
		waitingVectorName = new Vector();
		divDtoArray = new divDTO[20];
		for(int i = 0; i < 20; i++)
		{
			divDtoArray[i] = new divDTO();
			divDtoArray[i].setDivFlag(0);
		}
		divDtoArray[0].setDivFlag(1);
		divDtoArray[0].setDivBase(20);
		divDtoArray[0].setLength(180);
		readydata = new Object[6][4];
		runningdata = new Object[2][3];
		divdata = new Object[20][3];
		allocdata = new Object[20][3];
		String []col1 = {"进程","时间","优先级","状态"};
		String []col2 = {"进程","时间","优先级"};
		String []col3 = {"起址","长度","状态"};
		String []col4 = {"起址","长度","占用进程"};  
		readyTable = new JTable(readydata,col1);
		//readyTable.setEnabled(false);
		runningTable = new JTable(runningdata,col2);
		runningTable.setRowHeight(22);
		runningTable.setEnabled(false);
		allocTable = new JTable(allocdata,col4);
		allocTable.setEnabled(false);
		divTable = new JTable(divdata,col3);
		divTable.setEnabled(false);
		divTable.setValueAt(String.valueOf(20),0,0);
		divTable.setValueAt(String.valueOf(180),0,1);
		divTable.setValueAt(String.valueOf(1),0,2);
		JScrollPane runningSP = new JScrollPane();
		JScrollPane readySP2 = new JScrollPane();
		JScrollPane divSP = new JScrollPane();
		JScrollPane allocSP = new JScrollPane();
		runningSP.getViewport().add(runningTable);
		readySP2.getViewport().add(readyTable);
		divSP.getViewport().add(divTable);
		allocSP.getViewport().add(allocTable);
		//int []prorityArray = new int[10];
		for(int i = 0;i < 10;i++)
		{
			prorityCom.addItem(i);//prorityArray[i] = i;
		}
	
		
		jobList = new JList();
		waitingList = new JList();
		JScrollPane readySP = new JScrollPane(readyList);
		JScrollPane jobSP = new JScrollPane(jobList);
		JScrollPane waitingSP = new JScrollPane(waitingList);
		

		
		newPanel.setSize(450,100);
		newPanel.setLocation(0,0);
		
		nameLabel.setSize(80,20);
		nameLabel.setLocation(10,5);
		nameText.setSize(100,25);
		nameText.setLocation(10,30);
		prorityLabel.setSize(80,20);
		prorityLabel.setLocation(120,5);
		prorityCom.setSize(100,25);
		prorityCom.setLocation(120,30);
		timeLabel.setSize(80,20);
		timeLabel.setLocation(230,5);
		timeText.setSize(100,25);
		timeText.setLocation(230,30);
		spaceLabel.setSize(80,20);
		spaceLabel.setLocation(340,5);
		spaceText.setSize(100,25);
		spaceText.setLocation(340,30);
		newButton.setSize(100,20);
		newButton.setLocation(320,70);
		
		waitingPanel.setSize(190,410);
		waitingPanel.setLocation(0,100);
		
		jobLabel.setSize(100,20);
		jobLabel.setLocation(10,2);
		jobSP.setSize(180,105);
		jobSP.setLocation(10,25);
		waitingLabel.setSize(100,20);
		waitingLabel.setLocation(10,129);
		waitingSP.setSize(180,105);
		waitingSP.setLocation(10,150);
		divLabel.setSize(100,20);
		divLabel.setLocation(10,253);
		divSP.setSize(180,113);
		divSP.setLocation(10,273);
		relaxButton.setSize(80,20);
		relaxButton.setLocation(110,388);
		
		readyPanel.setSize(260,410);
		readyPanel.setLocation(190,100);
		
		readyLabel.setSize(100,22);
		readyLabel.setLocation(10,2);
		allocLabel.setSize(100,20);
		allocLabel.setLocation(10,232);
		startButton.setSize(80,20);
		startButton.setLocation(177,388);
		susButton.setSize(80,20);
		susButton.setLocation(95,388);
		readySP2.setSize(250,117);
		readySP2.setLocation(10,25);
		runningLabel.setLocation(10,142);
		runningLabel.setSize(100,20);
		runningSP.setSize(250,65);
		runningSP.setLocation(10,167);
		allocSP.setSize(250,130);
		allocSP.setLocation(10,255);
		
		c.add(newPanel);
		newPanel.add(nameLabel);
		newPanel.add(nameText);
		newPanel.add(prorityLabel);
		newPanel.add(prorityCom);
		newPanel.add(timeText);
		newPanel.add(timeLabel);
		newPanel.add(newButton);
		newPanel.add(spaceLabel);
		newPanel.add(spaceText);
		
		c.add(waitingPanel);
		waitingPanel.add(jobLabel);
		waitingPanel.add(jobSP);
		waitingPanel.add(waitingLabel);
		waitingPanel.add(waitingSP);
		waitingPanel.add(divLabel);
		waitingPanel.add(divSP);
		waitingPanel.add(relaxButton);
		
		c.add(readyPanel);
		readyPanel.add(readyLabel);
		readyPanel.add(allocLabel);
		readyPanel.add(runningLabel);
		readyPanel.add(startButton);
		readyPanel.add(susButton);
		readyPanel.add(allocSP);
		readyPanel.add(runningSP);
		readyPanel.add(readySP2);
		
		
		jf.setSize(470,550);
		jf.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        jf.setLocationRelativeTo(null);
        jf.setVisible(true);
        
        startButton.addActionListener(new MyActionListener());
		newButton.addActionListener(new MyActionListener());
		susButton.addActionListener(new MyActionListener());
		relaxButton.addActionListener(new MyActionListener());
	}
	public void sus()
	{
		try
		{
			Thread.sleep(1000);
		}
		catch(Exception ex)
		{
						
		}
	}
	class MyActionListener implements ActionListener 
	{
		public void actionPerformed(ActionEvent e)
		{
			
			int count = 0;
			PcbDTO test = new PcbDTO();
			
			JButton jb = (JButton)e.getSource();
			int max = -1;
			
			if(jb == startButton)
			{
				//while(true)
				//{
					int runAllocFlag = -1;
					
					if((String)runningTable.getValueAt(0,0)==null||(String)runningTable.getValueAt(0,0)=="")
					{
						try
						{
							Thread.sleep(0);
						}
						catch(Exception ex)
						{
						
						}
						//System.out.println("到3");
						for(int j = first;j != end; )
						{
							if(!readyDtoArray[j].getProcessState().equals("waiting"))
							{
								max = j;
								break;
							}
							j = (j+1)%6;
						}
					
						for(int j = first;j%6 != end; )
						{
							if(!readyDtoArray[j].getProcessState().equals("waiting"))
							{
							
								if(readyDtoArray[j].getPrority() > readyDtoArray[max].getPrority())
								{
									max = j;
								}
							
							}
							j = (j+1)%6;
						}
						if(max>=0)
						{
							a = readyDtoArray[max];
							readyDtoArray[max] = readyDtoArray[first];
							readyDtoArray[first] = a;
							
							readyTable.setValueAt(readyDtoArray[max].getProcessName(),max,0);
							readyTable.setValueAt(readyDtoArray[max].getRunTime(),max,1);
							readyTable.setValueAt(readyDtoArray[max].getPrority(),max,2);
							readyTable.setValueAt(readyDtoArray[max].getProcessState(),max,3);
							readyTable.setValueAt("",first,0);
							readyTable.setValueAt("",first,1);
							readyTable.setValueAt("",first,2);
							readyTable.setValueAt("",first,3);
							runningTable.setValueAt(a.getProcessName(),0,0);
							runningTable.setValueAt(a.getRunTime(),0,1);
							runningTable.setValueAt(a.getPrority(),0,2);
							readyDtoArray[first].setRunTime(readyDtoArray[first].getRunTime()-1);
							if(0 != readyDtoArray[first].getPrority())
							{
								readyDtoArray[first].setPrority(readyDtoArray[first].getPrority()-1);
							}
					
							first = (first+1)%6;
						}
						else
						{
							System.out.println("cpu等待中……");
						}
					
					}
					else 
					{
						/*try
						{
							Thread.sleep(2000);
						}
						catch(InterruptedException e1)
						{
							System.out.println(e1);
						}*/
						//System.out.println("到1");
						runningTable.setValueAt("",0,0);
						runningTable.setValueAt("",0,1);
						runningTable.setValueAt("",0,2);
						//如果运行时间为0则撤销进程，否则将进程重新添加到就绪队列中
						if( a.getRunTime()<=0)
						{
							//收回内存空间
							
							for(int i = 0;i < point; i++)
							{
								if(newSort[i].getBase()>=a.getBase())
								{
									newSort[i] = newSort[i+1];
								}
							}
							point--;
							//设置内存分配表的内容
							for(int i = 0; i < point;i++)
							{
								allocTable.setValueAt(String.valueOf(newSort[i].getBase()),i,0);
								allocTable.setValueAt(String.valueOf(newSort[i].getLimit()),i,1);
								allocTable.setValueAt(newSort[i].getProcessName(),i,2);
							}
						    allocTable.setValueAt("",point,0);
							allocTable.setValueAt("",point,1);
							allocTable.setValueAt("",point,2);
							//把收回的内存加入到记录未分分区的数组
							int memoryEnd = 0;
							int location = 0;
							int up = -1;//
							int down = -1;
							for(int i = 0;i<20;i++)
							{
								if(divDtoArray[i].getDivFalg() == 1)
								{
									memoryEnd = divDtoArray[i].getDivBase()+divDtoArray[i].getLength();
									if(memoryEnd == a.getBase())
									{
										up = i;
									}
									if(divDtoArray[i].getDivBase() == (a.getBase()+a.getLimit()))
									{
										down = i;
									}
								}
							}
							if(up >= 0&&down >= 0)
							{
								divDtoArray[up].setLength((divDtoArray[up].getLength()+a.getLimit()+divDtoArray[down].getLength()));
								divDtoArray[down].setDivFlag(0);
								for(int i = (down+1); i < 20;i++)
								{
									if(divDtoArray[i].getDivFalg() == 1)
									{
										divDtoArray[i-1].setDivBase(divDtoArray[i].getDivBase());
							    		divDtoArray[i-1].setDivFlag(1);
							    		divDtoArray[i-1].setLength(divDtoArray[i].getLength());
										divDtoArray[i].setDivFlag(0);
									}
									else
									{
										divTable.setValueAt("",i-1,0);
										divTable.setValueAt("",i-1,1);
										divTable.setValueAt("",i-1,2);
										break;
									}
								}
							}
							else if(up >= 0&&down < 0)
							{
								divDtoArray[up].setLength((divDtoArray[up].getLength()+a.getLimit()));
							}
							else if(up < 0&&down >= 0)
							{
								divDtoArray[down].setLength((divDtoArray[down].getLength()+a.getLimit()));
								divDtoArray[down].setDivBase(a.getBase());
							}
							else if(up < 0&&down < 0)
							{
								for(int i = 0; i < 20; i++)
								{
									if(divDtoArray[i].getDivBase()>a.getBase()||divDtoArray[i].getDivFalg()==0)
									{
										location = i;
										break;
									}
								}
							    for(int i = 20; i >location;i--)
							    {
							    	if(divDtoArray[i-1].getDivFalg()==1)
							    	{
							    		divDtoArray[i].setDivBase(divDtoArray[i-1].getDivBase());
							    		divDtoArray[i].setDivFlag(1);
							    		divDtoArray[i].setLength(divDtoArray[i-1].getLength());
							    	}
							    }
							    divDtoArray[location].setDivBase(a.getBase());
							    divDtoArray[location].setDivFlag(1);
							    divDtoArray[location].setLength(a.getLimit());
								
							}
							//设置未分分区表的内容
							for(int i = 0; i < 20;i++)
							{
							    if(divDtoArray[i].getDivFalg()==1)
							    {
									divTable.setValueAt(String.valueOf(divDtoArray[i].getDivBase()),i,0);
									divTable.setValueAt(String.valueOf(divDtoArray[i].getLength()),i,1);
									divTable.setValueAt(String.valueOf(divDtoArray[i].getDivFalg()),i,2);
							    }
							}
							if(!jobDtoVector.isEmpty())
							{
							    int runLength = 0;
								PcbDTO jobToReady = (PcbDTO)jobDtoVector.elementAt(0);
								for(int i = 0; i < 20; i++)
								{
									if(divDtoArray[i].getDivFalg() == 1)
									{
										if(divDtoArray[i].getLength() >= jobToReady.getLimit())
										{
											runAllocFlag = i;
											break;
										}
									}
								}
								if(runAllocFlag >= 0)
								{
									jobDtoVector.removeElementAt(0);
									jobVectorName.remove(jobVectorName.indexOf(jobToReady.getProcessName()));
									jobList.setListData(jobVectorName);
									jobToReady.setProcessState(PcbDTO.Ready);
									jobToReady.setBase(divDtoArray[runAllocFlag].getDivBase());
									runLength = divDtoArray[runAllocFlag].getLength()- jobToReady.getLimit();
									if(runLength == 0)
									{
										int i = runAllocFlag;
										divDtoArray[i].setDivFlag(0);
										for(; i < 19;i++)
										{
								
											if(divDtoArray[i+1].getDivFalg() == 1)
											{
												divDtoArray[i] = divDtoArray[i+1];
												divDtoArray[i+1].setDivFlag(0);
											}
											divTable.setValueAt(String.valueOf(divDtoArray[i].getDivBase()),i,0);
											divTable.setValueAt(String.valueOf(divDtoArray[i].getLength()),i,1);
											divTable.setValueAt(String.valueOf(divDtoArray[i].getDivFalg()),i,2);
										}
										divTable.setValueAt(String.valueOf(divDtoArray[i].getDivFalg()),i,2);
									}
									else if(runLength > 0)
									{
										int c2 = divDtoArray[runAllocFlag].getDivBase()+ jobToReady.getLimit();
										divDtoArray[runAllocFlag].setDivBase(c2);
										divDtoArray[runAllocFlag].setLength(runLength);
										divTable.setValueAt(String.valueOf(c2),runAllocFlag,0);
										divTable.setValueAt(String.valueOf(runLength),runAllocFlag,1);
										divTable.setValueAt(String.valueOf(divDtoArray[runAllocFlag].getDivFalg()),runAllocFlag,2);
							
									}
								
									readyDtoArray[end] = jobToReady;
									readyTable.setValueAt(jobToReady.getProcessName(),end,0);
									readyTable.setValueAt(jobToReady.getRunTime(),end,1);
									readyTable.setValueAt(jobToReady.getPrority(),end,2);
									readyTable.setValueAt(jobToReady.getProcessState(),end,3);
									end = (end+1)%6;
									int runi = 0;//用于记录当前新生成的PcbDTO对象应该插入到newSort中的位置
									for(; runi < point; runi++)
									{
										if(jobToReady.getBase() < newSort[runi].getBase())
										{
											break;
										}
									}
									//如果不是插入到数组末尾，则把比它大的都向后挪一位并设置JTable中的显示
									for(int i = point; i > runi; i--)
									{
										newSort[i] = newSort[i-1];
										allocTable.setValueAt(String.valueOf(newSort[i].getBase()),i,0);
										allocTable.setValueAt(String.valueOf(newSort[i].getLimit()),i,1);
										allocTable.setValueAt(newSort[i].getProcessName(),i,2);
									}
						
									//插入新生成的对象
									newSort[runi] = jobToReady;
									allocTable.setValueAt(String.valueOf(jobToReady.getBase()),runi,0);
									allocTable.setValueAt(String.valueOf(jobToReady.getLimit()),runi,1);
									allocTable.setValueAt(jobToReady.getProcessName(),runi,2);
									point++;
								}
								
							}
						}
						else 
						{
							
							readyDtoArray[end] = a;
							readyTable.setValueAt(a.getProcessName(),end,0);
							readyTable.setValueAt(a.getRunTime(),end,1);
							readyTable.setValueAt(a.getPrority(),end,2);
							readyTable.setValueAt(a.getProcessState(),end,3);
							end = (end+1)%6;
						}
					}
			    //}
				
			}
			else if(jb == newButton)// 点击新建进程对象
			{
				int newAllocFlag = -1;
				int newLength = 0;
				if(nameText.getText().trim().length() == 0)
				{
					JOptionPane.showMessageDialog(null,"进程名不能为空！");
				}
				else if(timeText.getText().trim().length() == 0)
				{
					JOptionPane.showMessageDialog(null,"运行时间不能为空");
				}
				else if(spaceText.getText().trim().length() == 0)
				{
					JOptionPane.showMessageDialog(null,"空间不能为空");
				}
				else
				{
					
					test.setRunTime(Integer.parseInt(timeText.getText()));
					test.setLimit(Integer.parseInt(spaceText.getText()));
					String s = prorityCom.getSelectedItem().toString();
					test.setPrority(Integer.parseInt(s));
					test.setProcessName(nameText.getText().trim());
					newDtoArray[count] = test;
					
					jobDtoVector.add(newDtoArray[count]);
					jobVectorName.add(newDtoArray[count].getProcessName());
					jobList.setListData(jobVectorName);
					count++;
					nameText.setText("");
					timeText.setText("");
					spaceText.setText("");
					PcbDTO b = (PcbDTO)jobDtoVector.elementAt(0);
					for(int i = 0; i < 20; i++)
					{
						if(divDtoArray[i].getDivFalg() == 1)
						{
							if(divDtoArray[i].getLength() >= b.getLimit())
							{
								newAllocFlag = i;
								break;
							}
						}
					}
					//在就绪队列未满且内存有足够空间时将后备队列jobDtoVetor中的对象添加到就绪队列中
					if((end + 2)%6 != first&&newAllocFlag >= 0)
					{
						jobDtoVector.removeElementAt(0);
						b.setProcessState(PcbDTO.Ready);
						b.setBase(divDtoArray[newAllocFlag].getDivBase());
						newLength = divDtoArray[newAllocFlag].getLength()- b.getLimit();
						if(newLength == 0)
						{
							int i = newAllocFlag;
							divDtoArray[i].setDivFlag(0);
							for(; i < 19;i++)
							{
								
								if(divDtoArray[i+1].getDivFalg() == 1)
								{
									divDtoArray[i] = divDtoArray[i+1];
									divDtoArray[i+1].setDivFlag(0);
								}
								divTable.setValueAt(String.valueOf(divDtoArray[i].getDivBase()),i,0);
								divTable.setValueAt(String.valueOf(divDtoArray[i].getLength()),i,1);
								divTable.setValueAt(String.valueOf(divDtoArray[i].getDivFalg()),i,2);
							}
							divTable.setValueAt(String.valueOf(divDtoArray[i].getDivFalg()),i,2);
						}
						else if(newLength > 0)
						{
							int c1 = divDtoArray[newAllocFlag].getDivBase()+ b.getLimit();
							divDtoArray[newAllocFlag].setDivBase(c1);
							divDtoArray[newAllocFlag].setLength(newLength);
							divTable.setValueAt(String.valueOf(c1),newAllocFlag,0);
							divTable.setValueAt(String.valueOf(newLength),newAllocFlag,1);
							divTable.setValueAt(String.valueOf(divDtoArray[newAllocFlag].getDivFalg()),newAllocFlag,2);
							
						}
						readyDtoArray[end] = b;
						jobVectorName.remove(jobVectorName.indexOf(b.getProcessName()));
						readyTable.setValueAt(b.getProcessName(),end,0);
						readyTable.setValueAt(b.getRunTime(),end,1);
						readyTable.setValueAt(b.getPrority(),end,2);
						readyTable.setValueAt("ready",end,3);
						end =(end+1)%6;
						
						int newi = 0;//用于记录当前新生成的PcbDTO对象应该插入到newSort中的位置
						for(; newi < point; newi++)
						{
							if(b.getBase() < newSort[newi].getBase())
							{
								break;
							}
						}
						//如果不是插入到数组末尾，则把比它大的都向后挪一位并设置JTable中的显示
						for(int i = point; i > newi; i--)
						{
							newSort[i] = newSort[i-1];
							allocTable.setValueAt(String.valueOf(newSort[i].getBase()),i,0);
							allocTable.setValueAt(String.valueOf(newSort[i].getLimit()),i,1);
							allocTable.setValueAt(newSort[i].getProcessName(),i,2);
						}
						
						//插入新生成的对象
						newSort[newi] = b;
						allocTable.setValueAt(String.valueOf(b.getBase()),newi,0);
						allocTable.setValueAt(String.valueOf(b.getLimit()),newi,1);
						allocTable.setValueAt(b.getProcessName(),newi,2);
						point++;
					}
					
				}
				
			}
			else if(jb == susButton)//  点击挂起
			{
				if(readyDtoArray[readyTable.getSelectedRow()] != null)// 判断是否等待
				{
					if(!readyDtoArray[readyTable.getSelectedRow()].getProcessState().equals("waiting"))
					{
						// 设置程序状态为等待
						readyDtoArray[readyTable.getSelectedRow()].setProcessState(PcbDTO.Waiting);
						// 设置图形界面的值为等待
						readyTable.setValueAt("waiting",readyTable.getSelectedRow(),3);
						// 将进程加入等待队列
						waitingDtoVector.add(readyDtoArray[readyTable.getSelectedRow()]);
						// 将进程名加入等待队列集合
						waitingVectorName.add(readyDtoArray[readyTable.getSelectedRow()].getProcessName());
						// 设置等待队列数据
						waitingList.setListData(waitingVectorName);
					}
					else
					{
						// 如果已经等待则提示挂起
						System.out.println("已挂起");
					}
				}
				else
				{
					JOptionPane.showMessageDialog(null,"请选择要挂起的进程");
					//System.out.println("请选择要挂起的进程");
				}
				
			}
			else if(jb == relaxButton)// 点击释放进程
			{
				String s = (String)waitingList.getSelectedValue();// 获取挂起进程的名字
				if(s != null)
				{
					waitingVectorName.remove(s);// 移除阻塞队列中的进程名
					PcbDTO p = new PcbDTO();
					for(int i = 0; i < waitingDtoVector.size(); i++)
					{
						p = (PcbDTO)waitingDtoVector.elementAt(i);
						if(s.equals(p.getProcessName()))
						{
							// 设置该进程状态为就绪
							p.setProcessState(PcbDTO.Ready);
							// 将该进程移除阻塞队列
							waitingDtoVector.remove(p);
							// 退出循环
							break;
						}
					}
					for(int i = 0;i < 6;i++)
					{
						if(s.equals(readyDtoArray[i].getProcessName()))
						{
							// 在图形界面中设置状态为就绪
							readyTable.setValueAt("ready",i,3);
							break;
						}
					}
					// 设置阻塞队列的值
					waitingList.setListData(waitingVectorName);
				}
				else
				{
					JOptionPane.showMessageDialog(null,"请选择要解挂的进程");
					//System.out.println("没有选择的进程");
				}
			}
		}
	}
	


	public static void main(String[] args)
	{
		new MainFrame();
	}
}
